import json
from typing import Optional

from fastadmin.widgets import Widget


class Display(Widget):
    """
    Parent class for all display widgets
    """


class InputOnly(Widget):
    """
    Only input without showing in display
    """


class Boolean(Display):
    template = "widgets/displays/boolean.html"


class Image(Display):
    template = "widgets/displays/image.html"

    def __init__(self, width: Optional[str] = None, height: Optional[str] = None):
        super().__init__(width=width, height=height)


class Json(Display):
    template = "widgets/displays/json.html"

    async def render(self, value: dict):
        return self.templates.get_template(self.template).render(
            value=json.dumps(value, indent=4, sort_keys=True),
        )
